﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Babyfur_translator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //string[] find = new string[] { "dada", "mama", "lurv", "ish", "yew", "nais", "kewl", "luv", "ai", "bu's", "wike", "tew", "gewd", "pwawmise", "siwwy", "dank", "dough", "dewe", "weawwy", "nicie", "hewe", "an's", "ou's", "wawm", "cewt", "faw", "i's", "naw", "pway", "wit'", "wha'", "cewd", "otay", "pawfec't", "pwecious", "tewsie" };
        //string[] replace = new string[] { "daddy", "mommy", "love", "is", "you", "nice", "cool", "love", "i", "but", "like", "to", "good", "promise", "silly", "thank", "though", "there", "very", "nice", "here", "and", "out", "warm", "cute", "for", "i'm", "no", "play", "with", "what", "could", "okay", "perfect", "precious", "too" };


        static string[] Find = { }, Replace = { };
        static string LoadFile(string Path)
        {
            string[] fInput ;
            try
            {
                fInput = File.ReadAllLines(Path);
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }

            string aFind = "";
            string aReplace = "";
            for (int i = 0; i < Find.Length; i++)
            {
                aFind += Find[i] + "\n";
                aReplace += Replace[i] + "\n";
            }
            foreach (string x in fInput)
            {
                string s = x.Trim().ToLower();
                string b = x.Trim();
                if (!s.Contains("[") || !s.Contains("]") ||
                    s == "" || !s.Contains(":"))
                    continue;

                s = s.Trim(new char[] { '[', ']' });
                b = b.Trim(new char[] { '[', ']' });
                string[] Prs = s.Split(':');
                Prs[1] = b.Split(':')[1];
                aFind += Prs[0].Trim() + "\n";
                aReplace += Prs[1].Trim() + "\n";
            }
            Find = aFind.TrimEnd('\n').Split('\n');
            Replace = aReplace.TrimEnd('\n').Split('\n');
            return "It warks lul.";
        }
        
        
        
        private void Form1_Load(object sender, EventArgs e)
        {
            //StringBuilder writedictionary = new StringBuilder();
            //for (int i = 0; i < find.Length; i++)
            //{
            //    writedictionary.Append("[" + find[i] + ":" + replace[i] + "]\n");
            //}
            //File.WriteAllText("./test.txt", writedictionary.ToString());
            if(LoadFile("./dictionary.txt") != "It warks lul.")
            {
            
             MessageBox.Show("Couldn't load dictionary, check for a valid 'dictionary.txt' in the program folder and restart the program."); }
        

            timer1.Start();
            MessageBox.Show("Translator application by Ced & Redskusky\nProgram written by Ced, Coding support, mental support, and the dictionary reading function base by Redskusky.\nTo add or edit a dictionary, Simply put a dictionary file in the same folder as the program.\nThe dictionary MUST be called 'dictionary.txt'.\nThe syntax for words in the dictionary is: [FOREIGN WORD:WORD TO BE TRANSLATED TO]\nExample can be found in the dictionary enclosed.\n\nCopyright® Ced & Redskusky.");

        }

        public void save_array()
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (richTextBox1.Text != "")
            {
                richTextBox2.Text = richTextBox1.Text.ToLower();

              for(int i = 0; i < Find.Length; i++)

                {


                    richTextBox2.Text = richTextBox2.Text.Replace(Find[i], Replace[i]);

                }

                
                

            }
        }

    }
}
